unit sqliteManger_u;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, cxGraphics,
  cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxStyles, cxCustomData,
  cxFilter, cxData, cxDataStorage, cxEdit, Data.DB, cxDBData, cxGridLevel,
  cxClasses, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, DBAccess, Uni, MemDS, UniProvider,
  SQLiteUniProvider, cxPCdxBarPopupMenu, cxPC, dxSkinsForm, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
  dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter, Vcl.Menus, cxButtons;

type
  TForm7 = class(TForm)
    UniConnection1: TUniConnection;
    UniQuery1: TUniQuery;
    UniQuery2: TUniQuery;
    UniDataSource1: TUniDataSource;
    UniDataSource2: TUniDataSource;
    SQLiteUniProvider1: TSQLiteUniProvider;
    dxSkinController1: TdxSkinController;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    cxGrid2DBTableView1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    cxGrid3DBTableView1: TcxGridDBTableView;
    cxGrid3Level1: TcxGridLevel;
    cxGrid3: TcxGrid;
    cxButton1: TcxButton;
    OpenDialog1: TOpenDialog;
    UniQuery1type: TMemoField;
    UniQuery1name: TMemoField;
    UniQuery1tbl_name: TMemoField;
    UniQuery1rootpage: TIntegerField;
    UniQuery1sql: TMemoField;
    cxGrid2DBTableView1type: TcxGridDBColumn;
    cxGrid2DBTableView1name: TcxGridDBColumn;
    cxGrid2DBTableView1tbl_name: TcxGridDBColumn;
    cxGrid2DBTableView1rootpage: TcxGridDBColumn;
    cxGrid2DBTableView1sql: TcxGridDBColumn;
    Panel4: TPanel;
    Panel5: TPanel;
    Memo2: TMemo;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    UniQuery3: TUniQuery;
    UniDataSource3: TUniDataSource;
    procedure cxButton1Click(Sender: TObject);
    procedure cxGrid2DBTableView1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form7: TForm7;

implementation

{$R *.dfm}

procedure TForm7.Button1Click(Sender: TObject);
  var
i:integer;
begin
  while cxGrid1DBTableView1.ColumnCount>0 do
  begin
     cxGrid1DBTableView1.Columns[0].Destroy;
  end;
  try
    UniQuery3.Close;
    UniQuery3.SQL.Clear;
    UniQuery3.SQL.Add(Memo2.text);
    UniQuery3.Open;
  except
    on e:Exception do
    begin
      Label1.caption:=e.Message;
    end;
  end;

  //cxGrid3DBTableView1.DataController.
  cxGrid1DBTableView1.DataController.CreateAllItems;
  for i:=0 to  cxGrid1DBTableView1.ColumnCount-1 do
  begin
     cxGrid1DBTableView1.Columns[i].Width:=100;
  end;
end;

procedure TForm7.cxButton1Click(Sender: TObject);
begin
  if OpenDialog1.Execute() and (OpenDialog1.FileName<>'') then
  begin
    UniConnection1.Connected:=false;
    UniConnection1.Database:= OpenDialog1.FileName;
    UniConnection1.Connected:=true;
    UniQuery1.Close;
    UniQuery1.SQL.Clear;
    UniQuery1.SQL.Add('SELECT * FROM sqlite_master where type=''table''');
    UniQuery1.Open;
  end;

end;

procedure TForm7.cxGrid2DBTableView1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
  var
i:integer;
begin
  while cxGrid3DBTableView1.ColumnCount>0 do
  begin
     cxGrid3DBTableView1.Columns[0].Destroy;
  end;

  UniQuery2.Close;
  UniQuery2.SQL.Clear;
  UniQuery2.SQL.Add('select * from ['+UniQuery1.FieldByName('name').AsString+']');
  UniQuery2.Open;

  //cxGrid3DBTableView1.DataController.
  cxGrid3DBTableView1.DataController.CreateAllItems;
  for i:=0 to  cxGrid3DBTableView1.ColumnCount-1 do
  begin
     cxGrid3DBTableView1.Columns[i].Width:=100;
  end;
end;

end.
